#include <stdio.h>

/**
 * 输出到文件
 */
int main() {
	// 收入和支出
	double income = 123.45, expenses = 987.65;
	int week = 7, year = 2006;
	FILE *output_stream;

	// 打开文件，设置访问模式为写入（write）,文件不存在时会创建文件
	output_stream = fopen("C3_4.OUT", "w");
	// 输出到文件
	fprintf(output_stream, "Week = %d\n"
						   "Year = %d\n", week, year);
	fprintf(output_stream, "Income = %.2lf\n"
						   "Expenses = %.2lf", income, expenses);

	// 关闭文件
	fclose(output_stream);
}